

package com.example.administrator.caigou51.recyclerCard.cardView;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ab.util.AbFileUtil;
import com.example.administrator.caigou51.R;
import com.example.administrator.caigou51.activity.CheckBugGoodsActivity;
import com.example.administrator.caigou51.activity.CollectActivity;
import com.example.administrator.caigou51.activity.GBaseActivity;
import com.example.administrator.caigou51.activity.GoodsDetailsActivity;
import com.example.administrator.caigou51.activity.LoginActivity;
import com.example.administrator.caigou51.activity.StoreManagerActivity;
import com.example.administrator.caigou51.bean.CollectBean;
import com.example.administrator.caigou51.control.DialogGoodsBuy;
import com.example.administrator.caigou51.global.App;
import com.example.administrator.caigou51.global.Constant;
import com.example.administrator.caigou51.recyclerCard.basic.CardItemView;
import com.example.administrator.caigou51.recyclerCard.card.ZhuangQuCard2;
import com.example.administrator.caigou51.request.BaseResponse;
import com.example.administrator.caigou51.request.ICallBackForRequestServer;
import com.example.administrator.caigou51.request.RequestServerManager;
import com.example.administrator.caigou51.util.ImageUtil;
import com.example.administrator.caigou51.util.ToastUtil;
import com.example.administrator.caigou51.widget.dialog.SweetDialogManager;

import cn.pedant.SweetAlert.SweetAlertDialog;


public class ZhuangQuCard2View extends CardItemView<ZhuangQuCard2> {
 	private Context mContext;
    public ZhuangQuCard2View(Context context) {
        super(context);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public ZhuangQuCard2View(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        // TODO Auto-generated constructor stub
    }

    public ZhuangQuCard2View(Context context,
                             AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        mContext=context;
        // TODO Auto-generated constructor stub
    }
    private ImageView imageViewGoods;
    private ImageView imageViewGoodsTag;
    private TextView textViewName,textViewKuCun;
    private TextView textViewAddress;
    private LinearLayout linearlayoutLSJ;
    private TextView textViewPriceLSJLeft,textViewSellScopen;
    private TextView textViewRmbLeft;
    private TextView textViewPFJLeft,textViewStyleDesc;
    private ImageView imageViewCar,imageViewBHSQ;
    private View viewLine;
    @Override
    public void build(final ZhuangQuCard2 card) {
        // TODO Auto-generated method stub
        super.build(card);
        imageViewGoods = (ImageView) findViewById(R.id.imageViewGoods);
        imageViewBHSQ= (ImageView) findViewById(R.id.imageViewBHSQ);
        imageViewGoodsTag = (ImageView) findViewById(R.id.imageViewGoodsTag);
        textViewName = (TextView) findViewById(R.id.textViewName);
        textViewSellScopen= (TextView) findViewById(R.id.textViewSellScopen);
        textViewAddress = (TextView) findViewById(R.id.textViewAddress);
        linearlayoutLSJ = (LinearLayout) findViewById(R.id.linearlayoutLSJ);
        textViewPriceLSJLeft = (TextView) findViewById(R.id.textViewPriceLSJLeft);
        textViewRmbLeft = (TextView) findViewById(R.id.textViewRmbLeft);
        textViewPFJLeft = (TextView) findViewById(R.id.textViewPFJLeft);
        textViewStyleDesc= (TextView) findViewById(R.id.textViewStyleDesc);
        textViewKuCun= (TextView) findViewById(R.id.textViewKuCun);
        imageViewCar = (ImageView) findViewById(R.id.imageViewCar);
        viewLine=findViewById(R.id.viewLine);
        imageViewCar.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogGoodsBuy.TaskAddCar("1",null,(GBaseActivity) mContext,card.getGoodsBean().getItemid(),true);
            }
        });
        //(1代表全国，2代表限广东）
        if ("2".equals(card.getGoodsBean().getSale_range())) {
            textViewSellScopen.setText("销售范围:广东省");
        }else
        {
            textViewSellScopen.setText("销售范围:全国");
        }
        //库存
        if (!TextUtils.isEmpty(card.getGoodsBean().getAmount())) {
            textViewKuCun.setText("库存: "+card.getGoodsBean().getAmount());
        }
        if (!TextUtils.isEmpty(card.getGoodsBean().getAmount()) && Integer.parseInt(card.getGoodsBean().getAmount())==0)
        {
            imageViewCar.setVisibility(View.GONE);
            imageViewBHSQ.setVisibility(VISIBLE);
        }else
        {
            imageViewCar.setVisibility(View.VISIBLE);
            imageViewBHSQ.setVisibility(View.GONE);
        }
        imageViewBHSQ.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (App.getUserBean()!=null) {
                    Intent intent = new Intent(mContext, CheckBugGoodsActivity.class);
                    intent.putExtra(GoodsDetailsActivity.TagGoodsDetailBean, card.getGoodsBean());
                    mContext.startActivity(intent);
                }else
                {
                    Intent intent=new Intent(mContext, LoginActivity.class);
                    mContext.startActivity(intent);
                }
            }
        });
        //直降和满减
        //判断促销信息
        if (GoodsDetailCardView.Tag_PuTong.equals(card.getGoodsBean().getPromotion()))
        {

            imageViewGoodsTag.setVisibility(View.GONE);
            textViewStyleDesc.setText("批发价：");
            textViewPFJLeft.setText(card.getGoodsBean().getShip_price());
        } else if (GoodsDetailCardView.Tag_ZhiJiang.equals(card.getGoodsBean().getPromotion()))
        {
            imageViewGoodsTag.setVisibility(View.VISIBLE);
            imageViewGoodsTag.setImageResource(R.drawable.icon_zj);
            textViewStyleDesc.setText("促销价：");
            textViewPFJLeft.setText(card.getGoodsBean().getPromotion_price());
        }else if (GoodsDetailCardView.Tag_ZheKou.equals(card.getGoodsBean().getPromotion()))
        {
            imageViewGoodsTag.setVisibility(View.VISIBLE);
            imageViewGoodsTag.setImageResource(R.drawable.icon_zk);
            textViewStyleDesc.setText("促销价：");
            textViewPFJLeft.setText(card.getGoodsBean().getPromotion_price());
        }else
        {
            imageViewGoodsTag.setVisibility(View.GONE);
            textViewStyleDesc.setText("批发价：");
            textViewPFJLeft.setText(card.getGoodsBean().getShip_price());
        }
        if (card.isShowBottomLine())
        {
            viewLine.setVisibility(View.VISIBLE);
        }else
        {
            viewLine.setVisibility(View.GONE);
        }
        if (card.getGoodsBean()!=null)
        {
            App.displayImageHttpOrFile(card.getGoodsBean().getThumb(),imageViewGoods, ImageUtil.OptionsActivity());

            textViewName.setText(card.getGoodsBean().getTitle()+"  "+card.getGoodsBean().getProduct_spec());
            textViewAddress.setText(card.getGoodsBean().getCorporation());
            textViewPriceLSJLeft.setText(card.getGoodsBean().getPrice());
            //判断是否会员
            if (App.getUserBean()!=null && App.getUserBean().getIs_verified()==App.PassValue)
            {

                textViewRmbLeft.setVisibility(View.VISIBLE);
            }else
            {
                textViewPFJLeft.setText("会员可见");
                textViewRmbLeft.setVisibility(View.GONE);

            }
        }else
        {
            App.displayImageHttpOrFile("",imageViewGoods, ImageUtil.OptionsActivity());
            textViewName.setText("");
            textViewAddress.setText("");
            textViewPriceLSJLeft.setText("");
        }
        setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent(mContext, GoodsDetailsActivity.class);
                intent.putExtra(GoodsDetailsActivity.GOODSID,card.getGoodsBean().getItemid());
                mContext.startActivity(intent);

                if (((GBaseActivity)mContext).getLocalClassName().contains("GoodsDetail"))
                    ((GBaseActivity)mContext).finish();
            }
        });


    }

}
